package com.zw.cc.stock.controller;

import com.zw.cc.stock.cache.SelectCache;
import com.zw.cc.stock.model.vo.PolicyVo;
import com.zw.cc.stock.model.vo.StocksVo;
import com.zw.cc.stock.service.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * Created by zwz
 * date 2016/11/23
 * project com.zw.thy.controller
 */
@RestController
public class PolicyController {


    @Autowired
    private PolicyService policyService;

    @RequestMapping("/query")
    public List<PolicyVo> query() {
        List<PolicyVo> list = new ArrayList<>();
        policyService.getStocksVoList().forEach(v->{
            list.add(new PolicyVo(v.getCode(),v.getName(), SelectCache.getRByCode(v.getCode())));
        });
        return list;
    }

    @RequestMapping("/refresh")
    public String refresh() {
        for(StocksVo stocksVo : policyService.getStocksVoList()) {
            policyService.calculate(stocksVo.getCode());
        }
        return "SUCCESS";
    }

}
